package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.mobile.bo.TWfActivityInstanceAddBo;
import com.ruoyi.system.mobile.bo.TWfActivityInstanceEditBo;
import com.ruoyi.system.mobile.bo.TWfActivityInstanceQueryBo;
import com.ruoyi.system.basicInformation.service.ITWfActivityInstanceService;
import com.ruoyi.system.basicInformation.vo.TWfActivityInstanceVo;
import com.ruoyi.system.mobile.service.ActivityInstanceService;
import com.ruoyi.system.mobile.vo.ActivityInstanceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 案件流程Controller
 * 
 * @author ruoyi
 * @date 2021-05-19
 */
@Api(value = "案件流程控制器", tags = {"案件流程管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/mobile/instance")
public class ActivityInstanceController extends BaseController {

    private final ActivityInstanceService iTWfActivityInstanceService;

    /**
     * 查询案件流程列表
     */
    @ApiOperation("查询案件流程列表")
    @GetMapping("/list")
    public TableDataInfo<ActivityInstanceVo> list(TWfActivityInstanceQueryBo bo) {
        startPage();
        List<ActivityInstanceVo> list = iTWfActivityInstanceService.queryList(bo);
        return getDataTable(list);
    }



    /**
     * 获取案件流程详细信息
     */
    @ApiOperation("获取案件流程详细信息")
    @GetMapping("/{id}")
    public AjaxResult<ActivityInstanceVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iTWfActivityInstanceService.queryById(id));
    }

    /**
     * 新增案件流程
     */
    @ApiOperation("新增案件流程")
    @Log(title = "案件流程", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TWfActivityInstanceAddBo bo) {
        return toAjax(iTWfActivityInstanceService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改案件流程
     */
    @ApiOperation("修改案件流程")
    @Log(title = "案件流程", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TWfActivityInstanceEditBo bo) {
        return toAjax(iTWfActivityInstanceService.updateByEditBo(bo) ? 1 : 0);
    }


}
